# -*- python -*-
# Copyright (C) 2003, Charles Wang.
# Author:  Charles Wang <charles@linux.net.cn>
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANT; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public LIcense for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA.

import os.path
import string

Import('env', 'mi_config', 'depInstall', 'MbPkgMaker')


class MagicbooterMaker(MbPkgMaker):
    alias = 'magicbooter'
    name = 'magicbooter'
    version = ''
    build_prefix = '$build_root/magicbooter'
    install_prefix = '$mbdestdir'
    LINKFLAGS = '-static'

    install_map = {'sbin/': ['magicbooter']}
    conf_cmds = []

    def prepare(self):
        env = self.env
        if not mi_config.nonewt:
            self.source_list = ['magicmain.c', 'magicbooter.c',
                                'search.c', 'choose.c', 'loadre.c', 'loadscsidrv.c', 'loadfloppy.c',
                                'search_ether.c', 'ethercard.c', 'gateway_dns.c', 'langset.c',
                                'utils.c', 'mblog.c', 'spec.c', 'newtutils.c',
                                'mount_guess_fstype2.c', 'sundries.c',
                                'detect_hardware.c', 'newtprog.c']
            self.lib_list = ['kudzu', 'pci', 'newt', 'slang', 'm', 'volume_id']
        else:
            self.source_list = ['magicmain.c', 'magicbooter.c',
                                'search.c', 'choose.c', 'loadre.c', 'loadfloppy.c',
                                'langset.c',
                                'utils.c', 'mblog.c', 'spec.c', 'newtutils.c',
                                'mount_guess_fstype2.c', 'sundries.c',
                                'detect_hardware.c']
            self.lib_list = ['kudzu', 'pci', 'volume_id']
            env.Append(CPPDEFINES = {'NONEWT' : '1'})

        if mi_config.useudev:
            self.source_list.append('switchroot.c')
        self.lib_list.extend(['applets', 'unarchive', 'bb', 'coreutils']) # busybox libs

        env.BuildDir('$build_prefix', '#MagicBooter/magic.booter', 0)
        env.Clean('$build_prefix/magicbooter', '$build_prefix')

    def build(self):
        env = self.env
        env.Alias(self.alias, Alias('mblib'))
        env.Alias(self.alias,
                  env.Program('$build_prefix/magicbooter',
                              self.path_prefix('$build_prefix', self.source_list),
                              LIBS = self.lib_list))


pkg = MagicbooterMaker(env)
pkg.make()
env.Alias('mbroot_src', 'magicbooter')
